package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.GoodsClassifyDao;
import com.yazi.mxz.common.entity.beans.Company;
import com.yazi.mxz.common.entity.beans.GoodsClassify;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("goodsClassifyDao")
public class GoodsClassifyDaoImpl extends BasicDao<GoodsClassify> implements GoodsClassifyDao {

	
	public GoodsClassifyDaoImpl() {
		super(GoodsClassify.class);
		
	}

	@Override
	public Criteria getExample(GoodsClassify classify, String searchWord) {
		Criteria c = super.getExample(classify, searchWord);
		
		// 关联对象条件
		if (null != classify) {
			// 父类
			GoodsClassify parent = classify.getGoodsClassify();
			if (null != parent) {
				// 父类ID
				Long parentId = parent.getClassifyId();
				if (null != parentId) {
					c.add(Restrictions.eq("goodsClassify.classifyId", parentId));
				} else {
					// ...父类其它条件
				}
			}			
			// 企业
			Company company = classify.getCompany();
			if (null != company) {
				// 企业ID
				if (null != company.getCompanyId()) {
					c.add(Restrictions.eq("company.companyId", company.getCompanyId()));
				} else {
					// ...企业其它条件
				}
			}
			// ...其它关联对象条件
		}
		
		// ...关键字searchWord条件
		
		return c;
	}

	@Override
	public int delete(long classifyId) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("classify_id", classifyId);
		return executeUpdate("delByClassifyIdSql", param);
	}
	
}
